package com.zq.zqmanager.dynamicsql;

import com.zq.zqmanager.entity.Cat;
import org.apache.ibatis.jdbc.SQL;

/**
 * @program: zqmanager
 * @Date: 2020/2/25 20:41
 * @Author: zhengqiang
 * @Description:
 */
public class CatDynamicSqlProvider {

    public String select(Cat cat){
        return new SQL(){
            {
                SELECT("*");
                FROM("cat");
                StringBuffer sb = new StringBuffer();
                if(cat.getCatAge()!=null) {
                    sb.append("and cat_age=").append(cat.getCatAge());
                }
                if(!"".equals(sb.toString())) {
                    WHERE(sb.toString().replaceFirst("and",""));
                }
            }
        }.toString();
    }

}
